<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
            <!-- <el-form-item label="训练航道" prop="channelId">
                <el-input v-model="queryParams.channelId" placeholder="请输入训练航道" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item> -->
            <el-form-item label="二级科目" prop="secondLevel">
                <el-select v-model="queryParams.secondLevel" placeholder="请选择训练项目" clearable size="small" style="width: 200px">
                    <el-option v-for="dict in secondLevelOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
                </el-select>
            </el-form-item>
            <el-form-item label="训练手段" prop="trainingMode">
                <el-select v-model="queryParams.trainingMode" placeholder="请选择训练手段" clearable size="small" style="width: 150px">
                    <el-option v-for="trainingWay in trainingModeOptions" :key="trainingWay.value" :label="trainingWay.label" :value="trainingWay.value" />
                </el-select>
            </el-form-item>
            <el-form-item v-if="queryParams.trainingMode=='0'" label="公里数" prop="rowingKilometersTwo">
                <el-select v-model="queryParams.rowingKilometersTwo" placeholder="请选择公里数" clearable size="small" style="width: 150px">
                    <el-option v-for="item in meterOptions" :key="item.dictValue" :label="item.remark" :value="item.dictValue" />
                </el-select>
            </el-form-item>
            <el-form-item v-else-if="queryParams.trainingMode=='1'" label="时间" prop="rowingClassHour">
                <el-select v-model="queryParams.rowingClassHour" placeholder="请选择时间" clearable size="small" style="width: 150px">
                    <el-option v-for="item in timeMeansOptions" :key="item.dictValue" :label="item.remark" :value="item.dictValue" />
                </el-select>
            </el-form-item>
            <el-form-item label="艇种">
                <el-select v-model="queryParams.boatType" placeholder="请选择" size="small" clearable style="width: 150px">
                    <el-option v-for="dict in boatTypeOptions" :key="dict.dictValue" :label="dict.dictValue" :value="dict.dictValue" />
                </el-select>
            </el-form-item>
            <el-form-item label="姓名" prop="sportsmanId" v-if="radio=='1'">
                <el-select v-model="queryParams.sportsmanId" placeholder="请选择姓名" clearable size="small" style="width: 150px">
                    <el-option v-for="dict in sportsmanNameList" :key="dict.id" :label="dict.name" :value="dict.id" />
                </el-select>
            </el-form-item>
            <el-form-item label="日期" prop="day">
                <el-date-picker clearable size="small" style="width: 200px" v-model="queryParams.day" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <!-- 课程区域 -->
        <div class="courseBox mb20" v-if="queryParams.trainingDayId">
            <el-card shadow="hover" class="planInfo">
                <ul>
                    <li>
                        <span class="label">一级科目：</span>
                        <span>{{trainingDayInfo.firstLevelName}}</span>
                    </li>
                    <li>
                        <span class="label">二级科目：</span>
                        <span>{{trainingDayInfo.secondLevelName}}</span>
                    </li>
                    <li>
                        <span class="label">四时：</span>
                        <span v-if="trainingDayInfo.fourSeasons=='beforedawn'">早晨</span>
                        <span v-else-if="trainingDayInfo.fourSeasons=='morning'">上午</span>
                        <span v-else-if="trainingDayInfo.fourSeasons=='afternoon'">下午</span>
                        <span v-else>晚上</span>
                    </li>
                    <li>
                        <span class="label">训练时长：</span>
                        <span>{{trainingDayInfo.startTime+' ~ '+trainingDayInfo.endTime}}</span>
                    </li>
                    <li>
                        <span class="label">公里数(m)：</span>
                        <span>{{trainingDayInfo.kilometers}}</span>
                    </li>
                    <li>
                        <span class="label">热身公里数(m)：</span>
                        <span>{{trainingDayInfo.warmUpKilometers}}</span>
                    </li>
                    <li>
                        <span class="label">组数：</span>
                        <span>{{trainingDayInfo.numberGroups}}</span>
                    </li>
                    <li>
                        <span class="label">训练手段：</span>
                        <span>{{trainingDayInfo.trainingMode==0?'公里数':'时间'}}</span>
                    </li>
                    <li>
                        <span class="label">间歇时间(分钟)：</span>
                        <span>{{trainingDayInfo.gapTim}}</span>
                    </li>
                    <li>
                        <span class="label">课时完成度(%)：</span>
                        <span>{{trainingDayInfo.completion*100}}</span>
                    </li>
                    <!-- <li>
                    <span class="label">课程要求：</span>
                    <span>{{trainingDayInfo.srMemo}}</span>
                </li> -->
                </ul>
                <el-collapse v-model="activeNames" @change="handleChange">
                    <el-collapse-item :title="title2" name="1">
                        <div class="details-box" v-if="schemeDetails">
                            <div class="name">方案名称：
                                <span style="color:#666">{{schemeDetails.name}}</span>
                            </div>
                            <div v-for="(item,index) in schemeDetails.schemeDetailsList" :key="item.id">
                                <div class="details-header">第{{index+1}}组</div>
                                <div class="details-row">
                                    <div class="label">课程要求</div>
                                    <div class="col">男</div>
                                    <div class="col">女</div>
                                </div>
                                <div class="details-row">
                                    <div class="label">总成绩</div>
                                    <div class="col">{{item.achievementMale}}</div>
                                    <div class="col">{{item.achievementFemale}}</div>
                                </div>
                                <div class="details-row">
                                    <div class="label">桨频</div>
                                    <div class="col">{{item.pulpMale}}</div>
                                    <div class="col">{{item.pulpFemale}}</div>
                                </div>
                                <div class="details-row" v-if="schemeDetails.firstLevel=='land_specific_training_dynamometer'">
                                    <div class="label">平均/500m</div>
                                    <div class="col">{{item.powerMale}}</div>
                                    <div class="col">{{item.powerFemale}}</div>
                                </div>
                                <div class="details-row">
                                    <div class="label">心率</div>
                                    <div class="col">{{item.heartRateMale}}</div>
                                    <div class="col">{{item.heartRateFemale}}</div>
                                </div>
                            </div>
                        </div>
                        <div v-else style="text-align:center;color:#909399">暂无方案</div>
                    </el-collapse-item>
                </el-collapse>
            </el-card>
        </div>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['trainingAchievement:trainingAchievement:export']">导出
                </el-button>
            </el-col>
            <el-col :span="4" class="radioBox">
                <el-radio v-model="radio" label="1" @change="changeTable">人艇</el-radio>
                <el-radio v-model="radio" label="2" @change="changeTable">艇支</el-radio>
            </el-col>
        </el-row>
        <!-- 以运动员为基础的表格 -->
        <el-table v-if="radio=='1'" v-loading="loading" :data="trainingAchievementList" border>
            <!-- <el-table-column type="selection" width="55" align="center" /> -->
            <el-table-column label="序号" type="index" width="55" align="center" :index="indexMethod" />
            <el-table-column label="训练日" align="center" prop="day" width="90px" />
            <el-table-column label="训练组" align="center" prop="groupName" />
            <el-table-column label="小组" align="center" prop="batch">
                <template slot-scope="scope">
                    小组{{scope.row.batch+1}}
                </template>
            </el-table-column>
            <el-table-column label="航道" align="center" prop="channelName">
                <template slot-scope="scope">
                    第{{parseInt(scope.row.channelName)+1}}航道
                </template>
            </el-table-column>
            <!-- <el-table-column label="训练手段" align="center" prop="trainingMode" width="90px" /> -->
            <!-- 新加 -->
            <el-table-column label="船速仪" align="center" prop="shipSpeedId" width="90px" />
            <el-table-column label="艇种" align="center" prop="boatType" />
            <!-- 新加 -->
            <el-table-column label="公里数" align="center" prop="rowingKilometers">
                <template slot-scope="scope">
                    <span v-show="scope.row.trainingMode=='0'">{{scope.row.rowingKilometers}}米</span>
                </template>
            </el-table-column>
            <!-- 新加 -->
            <el-table-column label="时长" align="center" prop="rowingClassHour">
                <template slot-scope="scope">
                    <span v-show="scope.row.trainingMode=='1'"> {{scope.row.rowingClassHour}}min</span>
                </template>
            </el-table-column>
            <el-table-column label="运动员" align="center" prop="sportsmanName" />
            <!-- 新加 -->
            <el-table-column label="总成绩" align="center" prop="achievement" width="100px" />
            <!-- 新加 -->
            <el-table-column label="分段成绩" align="center" prop="segmentedTiming" width="152px">
                <template slot-scope="scope">
                    <div v-if="scope.row.segmentedTiming">
                        <div v-for="(item,index) in scope.row.segmentedTiming.split(' ')" :key="index">
                            分段成绩{{index+1}}：{{item}}{{scope.row.trainingMode==0?'':'米'}}
                        </div>
                    </div>
                    <div v-else></div>
                </template>
            </el-table-column>
            <!-- 新加 -->
            <el-table-column label="桨频" align="center" prop="propellerFrequency" />
            <!-- 新加 -->
            <el-table-column label="平均船速" align="center" prop="shipSpeed" />
            <!-- 新加 -->
            <el-table-column label="最大船速" align="center" prop="maxShipSpeed" />
            <!-- 新加 -->
            <el-table-column label="桨数" align="center" prop="propellerNumber" />
            <!-- 新加 -->
            <el-table-column label="分段船数" align="center" prop="stageShipSpeed" />
            <!-- 新加 -->
            <el-table-column label="分段桨频" align="center" prop="stagePropeller">
                <template slot-scope="scope">
                    <div v-if="scope.row.stagePropeller">
                        <div v-for="(item,index) in scope.row.stagePropeller.split(' ')" :key="index">分段桨频{{index+1}}:{{item}}</div>
                    </div>
                    <div v-else></div>
                </template>
            </el-table-column>
            <el-table-column label="桨位" align="center" prop="oarType" />
            <el-table-column label="号位" align="center" prop="position" />
            <el-table-column label="心率" align="center" prop="heartRate" width="100px">
                <template slot-scope="scope">
                    <div v-if="scope.row.heartRate">
                        <div v-for="(item,index) in scope.row.heartRate.split(' ')" :key="index">心率{{index+1}}：{{item}}</div>
                    </div>
                    <div v-else></div>
                </template>
            </el-table-column>
            <!-- 新加 -->
            <el-table-column label="最大心率" align="center" prop="maxHeartRate" />
            <!-- 新加 -->
            <el-table-column label="平均心率" align="center" prop="averageHeartRate" />
            <!-- 新加 -->
            <el-table-column label="其他心率" align="center" prop="otherHeartRate">
                <template slot-scope="scope">
                    <div v-if="scope.row.otherHeartRate">
                        <div v-for="(item,index) in scope.row.otherHeartRate.split(' ')" :key="index">心率{{index+1}}:{{item}}</div>
                    </div>
                    <div v-else></div>
                </template>
            </el-table-column>
            <!-- 新加 -->
            <el-table-column label="其他乳酸" align="center" prop="otherLacticAcid">
                <template slot-scope="scope">
                    <div v-if="scope.row.otherLacticAcid">
                        <div v-for="(item,index) in scope.row.otherLacticAcid.split(' ')" :key="index">心率{{index+1}}:{{item}}</div>
                    </div>
                    <div v-else></div>
                </template>
            </el-table-column>
        </el-table>
        <!-- 以艇种为基础的表格 -->
        <el-table v-else v-loading="loading" :data="channelList" border>
            <!-- <el-table-column type="selection" width="55" align="center" /> -->
            <el-table-column label="序号" type="index" width="55" align="center" :index="indexMethod" key="1" />
            <el-table-column label="训练日" align="center" prop="day" width="90px" key="2" />
            <el-table-column label="训练组" align="center" prop="groupName" key="3" />
            <el-table-column label="小组" align="center" prop="batch" key="4">
                <template slot-scope="scope">
                    小组{{scope.row.batch+1}}
                </template>
            </el-table-column>
            <el-table-column label="航道" align="center" prop="channelName" key="5">
                <template slot-scope="scope">
                    第{{parseInt(scope.row.channelName)+1}}航道
                </template>
            </el-table-column>
            <!-- 新加 -->
            <el-table-column label="船速仪" align="center" prop="shipSpeedId" width="90px" key="6" />
            <el-table-column label="艇种" align="center" prop="boatType" key="7" />
            <!-- 新加 -->
            <el-table-column label="公里数" align="center" prop="rowingKilometers" key="8">
                <template slot-scope="scope">
                    <span v-show="scope.row.trainingMode=='0'">{{scope.row.rowingKilometers}}米</span>
                </template>
            </el-table-column>
            <!-- 新加 -->
            <el-table-column label="时长" align="center" prop="rowingClassHour" key="9">
                <template slot-scope="scope">
                    <span v-show="scope.row.trainingMode=='1'"> {{scope.row.rowingClassHour}}min</span>
                </template>
            </el-table-column>
            <el-table-column label="运动员" align="center" prop="sportsmanName" width="120px" key="10">
                <template slot-scope="scope">
                    <div v-for="(item,index) in scope.row.sportsmanName" :key="index" style="text-align:left">
                        运动员{{index+1}}：{{item}}
                    </div>
                </template>
            </el-table-column>
            <!-- 新加 -->
            <el-table-column label="总成绩" align="center" prop="achievement" width="100px" key="11" />
            <!-- 新加 -->
            <el-table-column label="分段成绩" align="center" prop="segmentedTiming" width="180px" key="12">
                <template slot-scope="scope">
                    <div v-if="scope.row.segmentedTiming">
                        <div v-for="(item,index) in scope.row.segmentedTiming.split(' ')" :key="index">
                            分段成绩{{index+1}}：{{item}}{{scope.row.trainingMode==0?'':'米'}}
                        </div>
                    </div>
                    <div v-else></div>
                </template>
            </el-table-column>
            <!-- 新加 -->
            <el-table-column label="桨频" align="center" prop="propellerFrequency" key="13" />
            <!-- 新加 -->
            <el-table-column label="平均船速" align="center" prop="shipSpeed" key="14" />
            <!-- 新加 -->
            <el-table-column label="最大船速" align="center" prop="maxShipSpeed" key="15" />
            <!-- 新加 -->
            <el-table-column label="桨数" align="center" prop="propellerNumber" key="16" />
            <!-- 新加 -->
            <el-table-column label="分段船数" align="center" prop="stageShipSpeed" key="17" />
            <!-- 新加 -->
            <el-table-column label="分段桨频" align="center" prop="stagePropeller" key="18">
                <template slot-scope="scope">
                    <div v-if="scope.row.stagePropeller">
                        <div v-for="(item,index) in scope.row.stagePropeller.split(' ')" :key="index">分段桨频{{index+1}}:{{item}}</div>
                    </div>
                    <div v-else></div>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script>
import { listTrainingAchievement, listSportsmanName, delTrainingAchievement, exportTrainingAchievement } from "@/api/training/trainingAchievement";
import { schemeDetails } from "@/api/training/scheme";
import { listTrainingGroupChannel, exportTrainingGroupChannel } from "@/api/training/trainingGroupChannel";
export default {
    name: "TrainingAchievement",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 总条数
            total: 0,
            // TrainingAchievement表格数据
            trainingAchievementList: [],
            //姓名下拉框数组
            sportsmanNameList: [],
            //一级训练项目字典
            secondLevelOptions: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                weekId: undefined,
                weekName: undefined,
                trainingDayId: undefined,
                groupId: undefined,
                groupName: undefined,
                boatType: undefined,
                channelId: undefined,
                channelName: undefined,
                sportsmanId: undefined,
                sportsmanName: undefined,
                position: undefined,
                heartRate: undefined,
                lacticAcid: undefined,
                firstLevel: "special_training_water",
                ctime: undefined,
                secondLevel: undefined,
                trainingMode: undefined,
                // rowingKilometers:undefined,
                rowingKilometersTwo: undefined,
                day:undefined
            },
            trainingDayInfo: '',
            activeNames: [],
            title2: '查看方案',
            schemeDetails: '',
            //训练手段
            trainingModeOptions: [
                { value: 0, label: '公里数' },
                { value: 1, label: '时间' }
            ],
            // 公里数（米）选项集合
            meterOptions: [],
            // 时间选项集合
            timeMeansOptions: [],
            // 艇种下拉框数组
            boatTypeOptions: [],
            radio: '1',
            channelList: [],
        };
    },
    created() {
        this.getNameList();
        //二级训练项目字典
        this.getDicts("special_training_water").then(response => {
            this.secondLevelOptions = response.data;
        });
        //训练公里数手段字典
        this.getDicts("kilometer").then(response => {
            this.meterOptions = response.data;
        });
        //训练时间手段字典
        this.getDicts("time_means").then(response => {
            this.timeMeansOptions = response.data;
        });
        //艇种字典
        this.getDicts("type_boat_support").then((response) => {
            this.boatTypeOptions = response.data;
        });
        this.getQueryParams()
        setTimeout(this.getList, 0)
    },
    methods: {
        // 设置序号方法
        indexMethod(index) {
            return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
        },
        // 切换表格
        changeTable(val) {
            this.getList()
        },
        // 如果从其他页面带参数进入当前页面，获取查询参数
        getQueryParams() {
            if (this.$route.query.row) {
                this.queryParams.secondLevel = this.$route.query.row.secondLevel
                this.queryParams.trainingMode = this.$route.query.row.trainingMode
                this.queryParams.rowingKilometersTwo = this.$route.query.row.kilometers
                this.queryParams.rowingClassHour = this.$route.query.row.classHour
                this.queryParams.trainingDayId = this.$route.query.row.id
                this.queryParams.schemeId = this.$route.query.row.schemeId
                this.queryParams.day = this.$route.query.row.day
                this.trainingDayInfo = this.$route.query.row
                this.getSchemeDetails()
            }
        },
        // 获取方案详情
        getSchemeDetails() {
            const id = this.queryParams.schemeId
            if (id) {
                schemeDetails(id).then(response => {
                    if (response.code == '200') {
                        this.schemeDetails = response.data
                    } else {
                        this.msgError('请求失败');
                    }
                })
            }
        },
        // 展开训练组
        handleChange(val) {
            if (val.length > 0) {
                this.title2 = '收起方案'
            } else {
                this.title2 = '查看方案'
            }
        },
        /** 查询TrainingAchievement列表 */
        getList() {
            this.loading = true;
            if (this.radio == '1') {
                listTrainingAchievement(this.queryParams).then(response => {
                    this.trainingAchievementList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            } else {
                listTrainingGroupChannel(this.queryParams).then(response => {
                    this.channelList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                })
            }
        },
        //赛事姓名集合
        getNameList() {
            this.loading = true;
            listSportsmanName(this.queryParams).then(response => {
                this.sportsmanNameList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        /** 导出按钮操作 */
        handleExport() {
            const queryParams = this.queryParams;
            let _this = this
            this.$confirm('是否确认导出所有数据项?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                if (_this.radio == '1') {
                    return exportTrainingAchievement(queryParams);
                } else {
                    return exportTrainingGroupChannel(queryParams);
                }
            }).then(response => {
                this.download(response.msg);
            }).catch(function () {
            });
        }
    }
};
</script>
<style lang="scss" scoped>
.details-box {
    text-align: center;
    .details-header {
        color: #303133;
        font-size: 16px;
        font-weight: bold;
        background: #dcdfe6;
        height: 40px;
        line-height: 40px;
    }
    .details-row {
        display: flex;
        height: 40px;
        line-height: 40px;
        border-bottom: 1px solid #dcdfe6;
        .label {
            border-left: 1px solid #dcdfe6;
            border-right: 1px solid #dcdfe6;
            color: #409eff;
            font-size: 15px;
            width: 20%;
        }
        .col {
            border-right: 1px solid #dcdfe6;
            width: 40%;
        }
    }
    .name {
        text-align: left;
        font-size: 15px;
        font-weight: bold;
        color: #606266;
    }
}
.courseBox {
    .planInfo {
        padding: 0;
        margin: 0;
        ul {
            padding: 0;
            margin: 0;
            li {
                float: left;
                list-style: none;
                color: #666;
                min-width: 250px;
                margin: 10px 30px 10px 0;
                font-size: 14px;
                .label {
                    font-size: 14px;
                    color: #606266;
                    font-weight: bold;
                }
            }
        }
    }
    .planInfo ul::after {
        display: block;
        clear: both;
        content: "";
    }
}
.radioBox {
    margin-top: 5px;
    margin-left: 30px;
}
</style>
<style lang="scss">
.courseBox {
    .el-collapse-item__header {
        color: #409eff;
        font-size: 15px;
        font-weight: bold;
        display: inline-block;
        border-bottom: none;
    }
    .el-collapse {
        border-top: none;
        border-bottom: none;
    }
}
</style>